<include file="public/header"/>
</head>
<body>
<div style="margin: 15px;" class="user-main">
    <div class="user-title">
        <span>代码生成工具</span>
    </div>
    <form class="layui-form mt20 J_ajaxForm" action="{:url('Generate/index')}" method="post">

        <div class="layui-form-item">
            <label class="layui-form-label">数据库表</label>
            <div class="layui-input-inline">
                <select name="table" lay-filter="test">
                    <option value=""></option>
                    <volist name="tables" id="vo">
                        <option value="{$vo.Name}">{$vo.Name} <span
                                style="color: blue">备注：{$vo.Comment}</span></option>
                    </volist>
                </select>

            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">控制器名称</label>
            <div class="layui-input-inline">
                <input type="text" name="controlname" id="controlname" class="layui-input layui-wd"
                       placeholder="请输入控制器名称"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">菜单名称</label>
            <div class="layui-input-inline">
                <input type="text" name="controltitle"  class="layui-input layui-wd"
                       placeholder="请输入菜单名称"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">where查询扩展</label>
            <div class="layui-input-inline" id="info">
                <table class="layui-table" style="width:400px;">
                    <thead>
                    <tr>
                        <th>字段名称</th>
                        <th>备注名称</th>
                    </tr>
                    </thead>
                </table>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">列表菜单</label>
            <div class="layui-input-inline">
                <input type="checkbox" name="info" class="layui-input layui-wd" title="查询" value="info">
                <input type="checkbox" name="add" class="layui-input layui-wd" title="添加" value="add">
                <input type="checkbox" name="edit" class="layui-input layui-wd" title="编辑" value="edit">
                <input type="checkbox" name="delect" class="layui-input layui-wd" title="删除" value="delect">
            </div>
        </div>

        <div class="layui-input-block mt20">
            <button class="layui-btn layui-btn-danger fr mr100" lay-submit lay-filter="iframebtn">生成代码</button>
        </div>
        <br>
        <div class="layui-form-item">
        <div class="layui-col-md6 " style="margin-left: 20px;">
            <div class="layui-row">
                <div class="layui-col-md12" style="padding: 10px;border: 1px dashed #aaa">
                    <blockquote class="layui-elem-quote">
                        <ol start="0">
                            <li>0.所有字段必须有<span class="layui-red">注释，注释为字段的名字，特殊字段有特殊注释格式</span></li>
                            <li>1.radio、select、checkbox、switch控件注释格式 <span class="layui-blue">状态名:1=xx,2=xx</span></li>
                            <li id="t2">
                                2.radio，select，checkbox类型建议使用，<span class="layui-red">数字 </span>标识不同状态而非字符串
                            </li>
                            <li>3.为了更好的区分radio,checkbox,select需要使用set,enum数据类型，生成成功后可手动将数据类型改为tinyint或者int系类型，前提是遵循<a
                                    href="#t2">上一条</a>规则
                            </li>
                            <li>4.switch控件比较特殊，值只能为0或者1，且1代表选中，也是就 <span class="layui-badge layui-btn-green">ON</span> 状态</li>
                            <li>5.默认初始控件都是text输入框</li>
                            <li>6.字段是否允许 <span class="layui-red">NULL</span> 决定字段的required校验</li>
                            <li>7.查询扩展功能需要功能选择中的查询被选中</li>
                            <li>8.查询条件默认为查询条件包括所有select,radio,switch的状态以及主键(建议使用ID)字段的输入框</li>
                            <li>9.选择表后查询拓展会加载字段，选择字段及是否模糊，可添加条件</li>
                            <li>10.<span class="layui-red">新!</span>新增其他表主键作为数据列，注释格式如下
                                xx:外联表的主键:外联表的显示字段(一般为title,name等,可以是外联表中的任意字段) eg: 文章表中的分类列，列名 <span class="layui-red">category_id</span>
                                注释 <span class="layui-red">所属分类:id:title</span>更多注意事项请查看<span class="layui-red"><a
                                        href="#selid" style="color: dodgerblue;">主键控件</a></span>
                            </li>
                        </ol>
                    </blockquote>
                    <table class="layui-table">
                        <thead class="layui-table-header">
                        <tr>
                            <th width="30%">控件类型</th>
                            <th>情况</th>
                        </tr>
                        </thead>
                        <tbody class="layui-table-body">
                        <tr>
                            <td rowspan="2">select控件</td>
                            <td>
                                数据类型为 <span class="layui-red">enum</span>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                数据类型为 <span class="layui-red">set</span>
                            </td>
                        </tr>
                        <tr>
                            <td rowspan="5">datetime日期选择框 本质是输入框，根据类型不同，加载的日期选择级别不同</td>
                            <td>
                                数据类型为 <span class="layui-red">year</span>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                数据类型为 <span class="layui-red">date</span>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                数据类型为 <span class="layui-red">time</span>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                数据类型为 <span class="layui-red">datetime</span>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                数据类型为 <span class="layui-red">timestamp</span>
                            </td>
                        </tr>
                        <tr>
                            <td rowspan="5">textarea 控件</td>
                            <td>
                                数据类型为 <span class="layui-red">longtext</span>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                数据类型为 <span class="layui-red">text</span>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                数据类型为 <span class="layui-red">mediumtext</span>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                数据类型为 <span class="layui-red">smalltext</span>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                数据类型为 <span class="layui-red">tinytext</span>
                            </td>
                        </tr>
                        <tr>
                            <td rowspan="2">number输入框，小数点长度决定步进属性</td>
                            <td>
                                数据类型为 <span class="layui-red">bigint</span>，<span class="layui-red">int</span>，<span
                                    class="layui-red">mediumint</span>，<span class="layui-red">smallint</span>，<span
                                    class="layui-red">tinyint</span>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                数据类型为 <span class="layui-red">decimal</span>，<span class="layui-red">double</span>，<span
                                    class="layui-red">float</span>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2" align="center">
                            <span class="layui-red">
                                字段名与数据类型共同决定控件，优先级高于数据类型
                            </span>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                datetime控件
                            </td>
                            <td>
                                以 <span class="layui-red">time</span>, <span class="layui-red">date</span>结尾的字段
                            </td>
                        </tr>
                        <tr>
                            <td>
                                radio单选框
                            </td>
                            <td>
                                以 <span class="layui-red">data</span>, <span class="layui-red">state</span>, <span
                                    class="layui-red">status</span>结尾的且数据类型为 <span style="color: orangered">enum</span> 的字段
                            </td>
                        </tr>
                        <tr>
                            <td>
                                checkbox复选框
                            </td>
                            <td>
                                以 <span class="layui-red">data</span>, <span class="layui-red">state</span>, <span
                                    class="layui-red">status</span>结尾的且数据类型为 <span style="color: orangered">set</span> 的字段
                            </td>
                        </tr>
                        <tr>
                            <td>
                                switch开关(默认0代表OFF,1代表ON)OFF与ON可通过注释更改，注释格式参考左侧demo
                            </td>
                            <td>
                                以 <span class="layui-red">switch</span> 结尾的且数据类型为 <span
                                    style="color: orangered">tinyint</span> 的字段
                            </td>
                        </tr>
                        <tr>
                            <td>
                                图片上传(jpg,gif,png等主流格式)
                            </td>
                            <td>
                                以 <span class="layui-red">image</span>, <span class="layui-red">images</span>, <span
                                    class="layui-red">avatar</span>, <span class="layui-red">avatars</span>结尾的且数据类型为 <span
                                    style="color: orangered">varchar</span>, <span style="color: orangered">char</span> 的字段
                            </td>
                        </tr>
                        <tr>
                            <td>
                                文件上传(格式不限)
                            </td>
                            <td>
                                以 <span class="layui-red">file</span>, <span class="layui-red">files</span> 结尾的且数据类型为 <span
                                    style="color: orangered">varchar</span>, <span style="color: orangered">char</span> 的字段
                            </td>
                        </tr>
                        <tr>
                            <td>
                                富文本编辑器
                            </td>
                            <td>
                                以 <span class="layui-red">content</span>, <span class="layui-red">description</span> 结尾的且数据类型为 <span
                                    style="color: orangered">text</span>,系列的字段
                            </td>
                        </tr>
                        <tr>
                            <td>
                                color颜色选择控件 IE不支持 默认text
                            </td>
                            <td>
                                以 <span class="layui-red">color</span> 结尾的且数据类型为 <span style="color: orangered">varchar</span>,<span style="color: orangered">char</span>的字段
                            </td>
                        </tr>
                        <tr>
                            <td id="selid">
                                <span class="layui-red">主键控件</span>
                            </td>
                            <td>
                                以 <span class="layui-red">_id</span> 结尾的且数据类型为 <span style="color: orangered">int</span>系列的字段<br>
                                其他要求:<br>
                                1.字段名必须为 <span class="layui-red">表名_id</span> 无需表名前缀，表名以及字段名严格遵守thinkphp规范，不可使用驼峰法命名。<br>
                                2.注释格式    <strong><span style="color: #dd4444">字段名</span>:<span style="color: #000d4d">id</span>:<span style="color: #007400">xx</span></strong>
                                <br>
                                <span style="color: #dd4444">字段名</span>为该字段(表名_id)在表中的代表意义<br>
                                <span style="color: #000d4d">id</span>为外联表的主键（不一定是id,但必须是主键）<br>
                                <span style="color: #007400">xx</span>为外联表展示的字段(一般为name、title等)
                                <br>
                                3.该字段的not null 不仅决定该字段是否必填，还决定该外联表的join方式。如果必填则inner 非必填 left
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
    </form>
    <br>

</div>
<include file="public/footer"/>
</body>
<script>
    layui.use('form', function () {
        var form = layui.form;
        form.on('select(test)', function (data) {
            var url1 = "{:url('Generate/tableinfo',['table'=>'ukid'])}";
            url1 = url1.replace('ukid', data.value);
            $.getJSON(url1, function (data1) {
                if (data1.status == "1") {
                    var str = '<table class="layui-table" style="width:400px;"><thead><tr><th>字段名称</th><th>查询类型</th><th>备注名称</th></tr></thead><tbody>';
                    $.each(data1.data, function (i, j) {
                        str += '<tr><td><input class="layui-input" type="checkbox" name="where['  + j.Field + ']" lay-skin="primary" title="'
                            + j.Field + '" value="eq" /></td><td><input type="checkbox" name="where['  + j.Field
                            + ']" title="模糊查询" value="like"  /></td><td><input type="checkbox" name="comment[]" title="'
                            + j.Comment + '" value="' + j.Comment + '"  /></td></tr>';
                    });
                    str += '</tbody></table>';
                    $('#info').html(str);
                    form.render()
                } else {
                    layer.alert(data1.msg, {icon: 2, anim: 6});
                }
            });
            var url2 = "{:url('Generate/controllername',['table'=>'ukid'])}";
            url2 = url2.replace('ukid', data.value);
            $.getJSON(url2, function (data1) {
                if (data1.status == "200") {
                    $('#controlname').val(data1.data);
                } else {
                    layer.alert(data1.msg, {icon: 2, anim: 6});
                }
            });
        });
    });
</script>
</html>